#!/usr/bin/env python
# coding: utf-8

# In[1]:


import pandas as pd
import matplotlib.pyplot as plt
import numpy as np


# In[2]:


df = pd.read_csv('./log.txt', header = None)
df.head()


# In[3]:


df = pd.read_csv('./log.txt', header = None, sep = '\t')
df.head()


# In[4]:


df.columns = ['id', 'api', 'count', 'res_time_sum', 'res_time_min', 'res_time_max', 'res_time_avg', 'interval', 'created_at']





df.sample(5) 
# In[7]:




df['api'].describe()


# In[11]:


df = df.drop('api', axis = 1) 


# In[12]:


df.head(2)


# In[13]:


df.info()


# In[14]:


df['created_at'].describe()


# In[15]:


df[df.created_at == '2019-05-01']


# In[16]:


df[(df.created_at >= '2019-05-01') & (df.created_at < '2019-05-02')]





# In[18]:


df.index = df['created_at']


# In[19]:


df['2019-05-01']


# In[20]:


df.info()


# In[21]:


df.index


# In[22]:


df.index = pd.to_datetime(df.created_at)




df.interval.describe()


# In[26]:


df.interval.unique()


# In[27]:


df = df.drop(['id', 'interval'], axis = 1)
df.head()



# In[30]:


df['count'].hist()  
plt.show()



df['count'].hist(bins = 30)
plt.show()
df['2019-5-1']['count'].plot()
plt.show()
df2 = df['2019-5-1']


df2 = df2[['count']].resample('1H').mean()
df2


# In[36]:


df2['count'].plot()
plt.show()


# In[40]:



plt.figure(figsize = (10, 5))  
df2['count'].plot(kind = 'bar')
plt.xticks(rotation = 45) 
plt.show()


# In[43]:

df['2019-5-1'][['count']].boxplot(showmeans = True, meanline = True)
plt.show()


# In[44]:


df[df['count'] > 20]


# In[45]:

df['2019-5-1']['res_time_avg'].plot()


# In[46]:


df['2019-5-1'][['res_time_avg']].boxplot()


# In[48]:


df2 = df['2019-5-1']
df2[df['res_time_avg'] > 1000] 


# In[49]:
df['2019-5-1'][['res_time_sum',	'res_time_min',	'res_time_max',	'res_time_avg']].plot()
plt.show()


# In[50]:


data = df['2019-5-1'].resample('20T').mean()
data[['res_time_sum',	'res_time_min',	'res_time_max',	'res_time_avg']].plot()
plt.show()





df['2019-5-1' : '2019-5-10']['count'].plot()
plt.show()


# In[53]:

# In[54]:


df['weekday'] = df.index.weekday


# In[55]:



df['weekend'] = df['weekday'].isin({5, 6})



# In[57]:


df.groupby('weekend')['count'].mean()


# In[58]:
df.groupby(['weekend', df.index.hour])['count'].mean()


# In[59]:

df.groupby(['weekend', df.index.hour])['count'].mean().plot()
plt.show()


# In[61]:

df.groupby(['weekend', df.index.hour])['count'].mean().unstack(level = 0)


# In[62]:


df.groupby(['weekend', df.index.hour])['count'].mean().unstack(level = 0).plot()
plt.show()


# In[ ]:




